//
//  UIPickerViewDemo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/4/3.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit

class UIPickerViewDemo: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
    var dataArray : Array<String>?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.gray
        let picker = UIPickerView()
        
        picker.dataSource = self
        picker.delegate = self
        self.view.addSubview(picker)
        
        picker.snp.makeConstraints { (maker) in
            maker.center.equalTo(self.view)
            maker.width.equalTo(200)
        }
        dataArray = ["1","2","3","4","5"]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 2
    }
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return (dataArray?.count)!
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return dataArray?[row]
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
